// #ifdef H5
import JSSDK from '@/utils/share/JSSDK.js'
// #endif
import { Common } from '@/utils/Common'
import store from '../../store'

export const ShareUtil = {
    // shareObject = {
    //		scene: "",
    // 		wxPersonalTitle: "",
    // 		wxPersonalDesc: "",
    // 		wxSpaceDesc: "",
    // 		imgUrl: "",
    // 		link: ""
    // }
    share(shareObject) {
        let str = shareObject.link.indexOf('&') === -1 ? "&" : ""
        let userStr = store.state.user ? store.state.user.uid : ''
        shareObject.link += str + 'shareUid=' + userStr

        // #ifdef H5
		if(Common.isWechat()){
			JSSDK.mpShare(shareObject)
		}
        // #endif

        // #ifdef MP-WEIXIN
        uni.showShareMenu({
            withShareTicket: true,
            title: shareObject.wxPersonalTitle,
            content: shareObject.wxPersonalDesc,
            imageUrl: shareObject.imgUrl,
            path: shareObject.link,
        })
        // #endif

        // #ifdef APP-PLUS
        let title = "", desc = ""

        if (shareObject.scene === "WXSceneSession") {
            title = shareObject.wxPersonalTitle
            desc = shareObject.wxPersonalDesc
        } else if (shareObject.scene === "WXSceneTimeline") {
            title = shareObject.wxSpaceDesc
        }
        uni.share({
            provider: "weixin",
            scene: shareObject.scene,
            type: 0,
            title: title,
            summary: desc,
            imageUrl: shareObject.imgUrl,
            href: shareObject.link,
            success: function (res) {
            },
            fail: function (err) {
            }
        });
        // #endif
    }
}
